package com.lineage.data.npc.other;

import com.lineage.data.executor.NpcExecutor;
import com.lineage.server.model.Instance.L1NpcInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.model.skill.L1SkillUse;
import com.lineage.server.serverpackets.S_CloseList;
import com.lineage.server.serverpackets.S_NPCTalkReturn;
import com.lineage.server.serverpackets.S_ServerMessage;
import com.lineage.server.serverpackets.ServerBasePacket;

public class Npc_EnchantBuff extends NpcExecutor {
  public static NpcExecutor get() {
    return new Npc_EnchantBuff();
  }
  
  public int type() {
    return 3;
  }
  
  public void talk(L1PcInstance pc, L1NpcInstance npc) {
    int mapId = npc.getMapId();
    if (mapId == 0 || mapId == 4) {
      pc.sendPackets((ServerBasePacket)new S_NPCTalkReturn(npc.getId(), "bs_04"));
    } else {
      pc.sendPackets((ServerBasePacket)new S_NPCTalkReturn(npc.getId(), "bs_08"));
    } 
  }
  
  public void action(L1PcInstance pc, L1NpcInstance npc, String cmd, long amount) {
    if (cmd.equals("a")) {
      if (pc.getInventory().consumeItem(40308, 3000L)) {
        int[] skillId = { 26, 42, 48 };
        int[] skillTime = { 1800, 1800, 960, 960, 960, 1000, 1000 };
        int i = 0;
        while (i < skillId.length) {
          L1SkillUse skillUse = new L1SkillUse();
          skillUse.handleCommands(pc, skillId[i], pc.getId(), pc.getX(), pc.getY(), skillTime[i], 4);
          i++;
        } 
      } else {
        pc.sendPackets((ServerBasePacket)new S_ServerMessage(189));
      } 
    } else {
      if (cmd.equalsIgnoreCase("1")) {
        pc.setAmount(1);
        String[] data = { String.valueOf(500), String.valueOf(1000), String.valueOf(1000), 
            String.valueOf(2000), String.valueOf(2000), String.valueOf(1) };
        pc.sendPackets((ServerBasePacket)new S_NPCTalkReturn(npc.getId(), "bs_m4", data));
        return;
      } 
      if (cmd.equalsIgnoreCase("2")) {
        pc.setAmount(5);
        String[] data = { String.valueOf(2500), String.valueOf(5000), String.valueOf(5000), 
            String.valueOf(10000), String.valueOf(10000), String.valueOf(5) };
        pc.sendPackets((ServerBasePacket)new S_NPCTalkReturn(npc.getId(), "bs_m4", data));
        return;
      } 
      if (cmd.equalsIgnoreCase("3")) {
        pc.setAmount(10);
        String[] data = { String.valueOf(5000), String.valueOf(10000), String.valueOf(10000), 
            String.valueOf(20000), String.valueOf(20000), String.valueOf(10) };
        pc.sendPackets((ServerBasePacket)new S_NPCTalkReturn(npc.getId(), "bs_m4", data));
        return;
      } 
      if (cmd.equalsIgnoreCase("4")) {
        pc.setAmount(100);
        String[] data = { String.valueOf(50000), String.valueOf(100000), String.valueOf(100000), 
            String.valueOf(200000), String.valueOf(200000), String.valueOf(100) };
        pc.sendPackets((ServerBasePacket)new S_NPCTalkReturn(npc.getId(), "bs_m4", data));
        return;
      } 
      if (cmd.equalsIgnoreCase("5")) {
        pc.setAmount(500);
        String[] data = { String.valueOf(250000), String.valueOf(500000), String.valueOf(500000), 
            String.valueOf(1000000), String.valueOf(1000000), String.valueOf(500) };
        pc.sendPackets((ServerBasePacket)new S_NPCTalkReturn(npc.getId(), "bs_m4", data));
        return;
      } 
      if (cmd.equals("A")) {
        int count = pc.getAmount();
        if (count <= 0) {
          pc.setAmount(0);
          pc.sendPackets((ServerBasePacket)new S_CloseList(pc.getId()));
          return;
        } 
        if (pc.getHighLevel() < 8) {
          pc.setAmount(0);
          pc.sendPackets((ServerBasePacket)new S_NPCTalkReturn(npc.getId(), "bs_m3"));
          return;
        } 
        int money = 500 * count;
        if (pc.getInventory().consumeItem(40308, money) && pc.getInventory().consumeItem(40090, count)) {
          pc.getInventory().storeItem(40860, count);
          pc.sendPackets((ServerBasePacket)new S_NPCTalkReturn(npc.getId(), "bs_m1"));
        } else {
          pc.sendPackets((ServerBasePacket)new S_NPCTalkReturn(npc.getId(), "bs_m2"));
        } 
        pc.setAmount(0);
        return;
      } 
    } 
    pc.sendPackets((ServerBasePacket)new S_CloseList(pc.getId()));
  }
}
